package com.aaa.inbound.service.impl;

import com.aaa.entity.inbound.Purchase;
import com.aaa.inbound.mapper.PurchaseMapper;
import com.aaa.inbound.service.PurchaseService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author aaa
 * @since 2020-11-25
 */
@Service
public class PurchaseServiceImpl extends ServiceImpl<PurchaseMapper, Purchase> implements PurchaseService {

    @Autowired
    private PurchaseMapper purchaseMapper;

    @Override
    public Page<Purchase> searchPurchase(Integer page, Integer limit, Purchase purchase) {
        Page<Purchase> pageinfo=new Page<>(page,limit);
        String purchaseno=purchase.getPurchaseno();
        String suppliername=purchase.getSuppliername();
        String state=purchase.getState();
        Long warehouseid=purchase.getWarehouseid();
        QueryWrapper<Purchase> queryWrapper=new QueryWrapper<>();
        if(StringUtils.isNotEmpty(purchaseno)){
            queryWrapper.like("purchaseno",purchaseno);
        }
        if(StringUtils.isNotEmpty(suppliername)){
            queryWrapper.like("suppliername",suppliername);
        }
        if(StringUtils.isNotEmpty(state)){
            queryWrapper.like("state",state);
        }
        if(warehouseid!=null){
            queryWrapper.like("warehouseid",warehouseid);
        }
        this.baseMapper.selectPage(pageinfo, queryWrapper);
        return pageinfo;
    }

    @Override
    public List<Map> findSupplier(Long warehouseid) {
        return baseMapper.findSupplier(warehouseid);
    }
}
